package cn.rongcloud.im.ui.view;

import android.animation.AnimatorSet;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.badgeview.BGABadgeTextView;
import cn.rongcloud.im.R;
import cn.rongcloud.im.ui.bean.MoudleChildBean;
import cn.rongcloud.im.ui.listener.OnChannelItemClicklistener;
import cn.rongcloud.im.ui.listener.UserActionListener;
import cn.rongcloud.im.ui.moudle.twocode.view.MyRecycleView;
import cn.rongcloud.im.utils.MeasureUtil;
import cn.rongcloud.im.utils.ScreenUtils;
import cn.rongcloud.im.utils.SpacesItemDecoration;


/**
 * 描述：
 * Created by zhaohl on 2017-3-15.
 */

public class ChannelTagView extends LinearLayout{
    /**
     * 频道显示列数
     */
    public int colums = 3;
    /**
     * 频道显示行间距、列间距
     */
    public int columnSpace = 1;
    /**
     * 已添加的频道数据集合
     */
    private ArrayList<MoudleChildBean> addedChannels = new ArrayList<>();
    /**
     * 未添加的频道数据集合
     */
    private ArrayList<MoudleChildBean> unAddedChannels = new ArrayList<>();
    /**
     * 已、未添加的频道adapter
     */
    private ChannelAdapter addedAdapter, unAddedAdapter;
    /**
     * 处理recyclerview手势的辅助类
     */
    private ItemTouchHelper itemTouchHelper;
    /**
     * 频道点击事件回调接口
     */
    private OnChannelItemClicklistener onChannelItemClicklistener;
    /**
     * 用户操作已添加频道的一些手势事件回调接口
     */
    private UserActionListener userActionListener;
    /**
     * 是否显示添加后的轨迹动画
     */
    private boolean showPahtAnim;
    /**
     * 固定position
     */
    private int fixedPos = -1;
    /**
     * 频道文字颜色
     */
    private int channelItemTxColor;
    /**
     * 频道文字大小
     */
    private int channelItemTxSize;
    /**
     * 栏目分组banner颜色
     */
    private int categoryAddedBannerBg, categoryUnAddedBannerBg;
    private MyRecycleView addedRecyclerView, unaddedRecyclerView;
    /**
     * 栏目分组标题textview
     */
    private TextView categaryAddedTopView, categrayUnAddedTopView;
    private AnimatorSet pathAnimator;
    /**每个Item的宽度*/
    private int mItemSize;
    /*Item的宽高比例*/
    private float mScale = (float) (3 / 2.0);
    /**上一次的点击时间,防止recycleView正在执行动画的点击导致的崩溃*/
    private long mPreClickTime;
    /**当前的点击时间,防止recycleView正在执行动画的点击导致的崩溃*/
    private long mNowClickTime;
    /**点击时间差*/
    private long mDuration = 200;

    public ChannelTagView(Context context) {
        this(context, null);
    }

    public ChannelTagView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public ChannelTagView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.channel_tag_style);
        showPahtAnim = array.getBoolean(R.styleable.channel_tag_style_showPathAnim, true);
        categoryAddedBannerBg = array.getResourceId(R.styleable.channel_tag_style_addedCategroyTitleBg, R.color.white);
        categoryUnAddedBannerBg = array.getResourceId(R.styleable.channel_tag_style_unAddedCategroyTitleBg, R.color.white);
        fixedPos = array.getInt(R.styleable.channel_tag_style_fixedPos, -1);
        colums = array.getInt(R.styleable.channel_tag_style_colums, colums);
        columnSpace = array.getDimensionPixelOffset(R.styleable.channel_tag_style_columnSpace, 1);
        channelItemTxColor = array.getColor(R.styleable.channel_tag_style_channelItemTxColor, 0xff000000);
        channelItemTxSize = array.getDimensionPixelOffset(R.styleable.channel_tag_style_channelItemTxSize, 39);
        setOrientation(VERTICAL);
        initParams();
        initView();
        setListenter();
    }

    /**
     * 初始化参数
     */
    private void initParams() {
        int width = ScreenUtils.getScreenWidth(getContext());
        mItemSize = width / colums;
    }




    /**
     * 设置监听
     */
    private void setListenter() {
    }

    private void initView() {
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.channel_tag_layout, this, true);
        addedRecyclerView = (MyRecycleView) contentView.findViewById(R.id.added_channel_recyclerview);
        unaddedRecyclerView = (MyRecycleView) contentView.findViewById(R.id.unAdded_channel_recyclerview);
        categaryAddedTopView = (TextView) contentView.findViewById(R.id.categray_added_title);
        categrayUnAddedTopView = (TextView) contentView.findViewById(R.id.categray_unadded_title);
        addedRecyclerView.setLayoutManager(new GridLayoutManager(getContext() , colums ){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        addedRecyclerView.addItemDecoration(new SpacesItemDecoration(columnSpace));
        unaddedRecyclerView.setLayoutManager(new GridLayoutManager(getContext() , colums){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        unaddedRecyclerView.addItemDecoration(new SpacesItemDecoration(columnSpace));
        itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
            @Override
            public boolean isItemViewSwipeEnabled() {
                return false;
            }

            @Override
            public boolean isLongPressDragEnabled() {
                return true;
            }

            @Override
            public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
                int dragFlag = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
                int swipeFlag = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
                return makeMovementFlags(dragFlag, swipeFlag);
            }

            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                int from = viewHolder.getAdapterPosition();
                int to = target.getAdapterPosition();
                if(addedChannels.get(from).isSpace()|| addedChannels.get(to).isSpace()
                        ||addedChannels.get(from).isNotMove() || addedChannels.get(to).isNotMove()){
                    return false;
                }


//                if (from == fixedPos) {
//                    return false;
//                }
//                if (to == fixedPos) {
//                    return false;
//                }
                MoudleChildBean item = addedChannels.remove(from);
                addedChannels.add(to,item);
                addedAdapter.notifyItemMoved(from, to);
                return true;
            }

            @Override
            public void onMoved(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, int fromPos, RecyclerView.ViewHolder target, int toPos, int x, int y) {
                super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y);
                initListPosition(addedChannels);
                if (userActionListener != null) {
                    userActionListener.onMoved(fromPos, toPos, addedChannels);
                }
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            }

            @Override
            public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
                int position = viewHolder.getAdapterPosition();
                if (!addedChannels.get(position).isSpace() && !addedChannels.get(position).isNotMove()) {
                    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
                }
            }

            @Override
            public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
                super.onSelectedChanged(viewHolder, actionState);
                if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
                    ViewCompat.setScaleX(viewHolder.itemView, 1.1f);
                    ViewCompat.setScaleY(viewHolder.itemView, 1.1f);
                }
            }

            @Override
            public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
                super.clearView(recyclerView, viewHolder);
                ViewCompat.setScaleX(viewHolder.itemView, 1.0f);
                ViewCompat.setScaleY(viewHolder.itemView, 1.0f);

            }
        });
        itemTouchHelper.attachToRecyclerView(addedRecyclerView);
        addedRecyclerView.setAdapter(addedAdapter = new ChannelAdapter(getContext(), R.layout.item_channel_view, addedChannels, true));
        unaddedRecyclerView.setAdapter(unAddedAdapter = new ChannelAdapter(getContext(), R.layout.item_channel_view, unAddedChannels, false));
        addedAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
//                ((BGABadgeTextView)view).hiddenBadge();
                if (onChannelItemClicklistener != null) {
                    onChannelItemClicklistener.onAddedChannelItemClick(view, position);
                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        unAddedAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                if (onChannelItemClicklistener != null) {
                    // 用户在这个回调处理自己的逻辑
                    onChannelItemClicklistener.onUnAddedChannelItemClick(view, position);
                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });

    }

    /**
     * 把数据添加到List中
     * @param toChannels
     * @param toAdapter
     * @param position
     * @param fromChannels
     * @param fromdAdapter
     * @param flag
     */
    private void addDataToList(ArrayList<MoudleChildBean> toChannels, ChannelAdapter toAdapter, int position
            , ArrayList<MoudleChildBean> fromChannels, ChannelAdapter fromdAdapter,boolean flag) {
//        removeLastSpaceViewInToList(toChannels ,toAdapter);
        MoudleChildBean item = removeViewInFromList(fromChannels , position,fromdAdapter);
        addViewToToList(item,toChannels ,toAdapter,flag);
        dealSpaceViewToToList(toChannels ,toAdapter);
        dealSpaceViewToFromList(fromChannels ,fromdAdapter );
    }

    /**
     * 对ToList进行空白View的处理
     * @param toChannels
     * @param toAdapter
     */
    private void dealSpaceViewToToList(ArrayList<MoudleChildBean> toChannels, ChannelAdapter toAdapter) {
        int count = 0;
        for(MoudleChildBean item : toChannels){
            if(!item.isSpace()) {
                ++count;
            }
        }
        int lenth = 0;
        if(count % colums == 1){
            while(true) {
                ++lenth;
                MoudleChildBean item = new MoudleChildBean();
                item.setMoudleChildName("");
                item.setSpace(true);
                toChannels.add(item);
                toAdapter.notifyItemInserted(toChannels.size() - 1);
                if(lenth == colums -1){
                    break;
                }
            }
        }else{
            toAdapter.notifyItemRemoved(toChannels.size()-1);
            toChannels.remove(toChannels.size()-1);
        }
    }

    /**
     * 对FromList的空白View进行处理
     * @param fromChannels
     * @param fromdAdapter
     */
    private void dealSpaceViewToFromList(ArrayList<MoudleChildBean> fromChannels, ChannelAdapter fromdAdapter) {
        int count = 0;
        for(MoudleChildBean item : fromChannels){
            if(!item.isSpace()) {
                ++count;
            }
        }
        //如果模完之后等于0，那么需要把多余的一行空白View删掉，如果不等0，那么添加一个空白View
        int lenth = 0;
        if(count % colums == 0){
            while (true){
                ++lenth;
                fromdAdapter.notifyItemRemoved(fromChannels.size()-1);
                fromChannels.remove(fromChannels.size()-1);
                if(lenth == colums -1){
                    break;
                }
            }
        }else{
            MoudleChildBean item =new MoudleChildBean();
            item.setMoudleChildName("");
            item.setSpace(true);
            fromChannels.add(item);
            fromdAdapter.notifyItemInserted(fromChannels.size()-1);
        }
    }

    /**
     * 把View添加到ToList中
     * @param item
     * @param toChannels
     * @param toAdapter
     * @param flag
     */
    private void addViewToToList(MoudleChildBean item, ArrayList<MoudleChildBean> toChannels
            , ChannelAdapter toAdapter,boolean flag) {
        boolean tag =false;
        for(int i = 0 ; i < toChannels.size() ; i++){
            if(toChannels.get(i).isSpace()){
                if(!flag){
                    toChannels.add(i , item);
                    toAdapter.notifyItemInserted(i);
                }else{
                    toChannels.add(0 , item);
                    toAdapter.notifyItemInserted(0);
                }
                tag = true;
                break;
            }
        }
        if(!tag){
            if(!flag) {
                toChannels.add(item);
                toAdapter.notifyItemInserted(toChannels.size() - 1);
            }else{
                toChannels.add(0,item);
                toAdapter.notifyItemInserted(0);
            }
        }
    }

    /**
     *  移除FromList中的对应的View
     * @param fromChannels
     * @param position
     * @param fromdAdapter
     * @return
     */
    private MoudleChildBean removeViewInFromList(ArrayList<MoudleChildBean> fromChannels, int position, ChannelAdapter fromdAdapter) {
        MoudleChildBean item = fromChannels.remove(position);
        fromdAdapter.notifyItemRemoved(position);
        return item;
    }



    /**
     * 初始化频道数据
     *
     * @param addedChannels   已添加的频道
     * @param unAddedChannels 未添加的频道
     */
    public void initChannels(ArrayList<MoudleChildBean> addedChannels, ArrayList<MoudleChildBean> unAddedChannels) {
        if (addedChannels != null) {
            this.addedChannels.clear();
            this.addedChannels.addAll(addedChannels);
            this.addedAdapter.notifyDataSetChanged();
        }
        if (unAddedChannels != null) {
            this.unAddedChannels.clear();
            this.unAddedChannels.addAll(unAddedChannels);
            this.unAddedAdapter.notifyDataSetChanged();
        }
    }

    ;

//
//    /**
//     * 开始轨迹动画
//     *
//     * @param tragetView
//     * @param position
//     */
//    private void startPahtAnim(final View tragetView, final int position) {
//        if (pathAnimator != null && pathAnimator.isRunning()) {
//            return;
//        }
//        View lastCheckedChild = addedRecyclerView.getChildAt(addedChannels.size() - 1);
//        Rect rectLast = new Rect();
//        int tragetX = 0;
//        int tragetY = 0;
//        int statusBarHeight = MeasureUtil.getStatusBarHeight((Activity) getContext());
//        if (null != lastCheckedChild) {
//            lastCheckedChild.getGlobalVisibleRect(rectLast);
//            if (addedChannels.size() % colums == 0) {// 换行
//                tragetX = addedRecyclerView.getLeft() + addedRecyclerView.getPaddingLeft() + columnSpace;
//                tragetY = rectLast.top + tragetView.getHeight() + 2 * columnSpace - statusBarHeight;
//            } else {
//                tragetX = rectLast.right + columnSpace * 2;
//                tragetY = rectLast.top - statusBarHeight;
//            }
//        } else {
//            rectLast.left = addedRecyclerView.getLeft() + addedRecyclerView.getPaddingLeft();
//            rectLast.top = addedRecyclerView.getTop() + addedRecyclerView.getPaddingTop();
//            tragetX = rectLast.left;
//            tragetY = rectLast.top;
//        }
//        Rect rectTarget = new Rect();
//        tragetView.getGlobalVisibleRect(rectTarget);
//        final Point point = new Point();
//        point.x = rectTarget.left;
//        point.y = rectTarget.top - statusBarHeight;
//        FloatItemViewManager.showFloatADwindow(getContext(), tragetView, unAddedChannels.get(position).title, point);
//
//        final Point updatePoint = new Point();
//        ValueAnimator animX = ValueAnimator.ofFloat(point.x, tragetX);
//        animX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//            @Override
//            public void onAnimationUpdate(ValueAnimator animation) {
//                float valueX = (float) animation.getAnimatedValue();
//                updatePoint.x = (int) valueX;
//                FloatItemViewManager.updateFloatViewPosition(updatePoint);
//            }
//        });
//        ValueAnimator animY = ValueAnimator.ofFloat(point.y, tragetY);
//        animY.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//            @Override
//            public void onAnimationUpdate(ValueAnimator animation) {
//                float valueY = (float) animation.getAnimatedValue();
//                updatePoint.y = (int) valueY;
//                FloatItemViewManager.updateFloatViewPosition(updatePoint);
//            }
//        });
//        final ChannelItem removeItem = unAddedChannels.remove(position);
//        pathAnimator = new AnimatorSet();
//        pathAnimator.setDuration(300);
//        pathAnimator.addListener(new Animator.AnimatorListener() {
//            @Override
//            public void onAnimationStart(Animator animation) {
//                unAddedAdapter.notifyItemRemoved(position);
//            }
//
//            @Override
//            public void onAnimationEnd(Animator animation) {
//                addedChannels.add(removeItem);
//                if(getResources().getString(R.string.finish).equals(mEditTextView.getText())){
//                    removeItem.hasIconShow =true;
//                }else if(getResources().getString(R.string.edit).equals(mEditTextView.getText())){
//                    removeItem.hasIconShow =false;
//                }
//                addedAdapter.notifyItemInserted(addedChannels.size() - 1);
//                FloatItemViewManager.hideFloatView();
//            }
//
//            @Override
//            public void onAnimationCancel(Animator animation) {
//
//            }
//
//            @Override
//            public void onAnimationRepeat(Animator animation) {
//
//            }
//        });
//        pathAnimator.play(animX).with(animY);
//        pathAnimator.start();
//
//    }


    /**
     * 设置编辑按钮状态
     */
    public void setEditorState(TextView mEditTextView){
        if(getResources().getString(R.string.finish).equals(mEditTextView.getText())){
            mEditTextView.setText(getResources().getString(R.string.edit));
            mEditTextView.setTextColor(getResources().getColor(R.color.white));
            for(MoudleChildBean item : addedChannels){
                if(!item.isSpace()) {
                    item.setHasIconShow(false);
                }
            }
            for(MoudleChildBean item : unAddedChannels){
                if(!item.isSpace()) {
                    item.setHasIconShow(false);
                }
            }
        }else if(getResources().getString(R.string.edit).equals(mEditTextView.getText())){
            mEditTextView.setText(getResources().getString(R.string.finish));
            mEditTextView.setTextColor(getResources().getColor(R.color.white));
            for(MoudleChildBean item : addedChannels){
                if(!item.isSpace()) {
                    item.setHasIconShow(true);
                }
            }
            for(MoudleChildBean item : unAddedChannels){
                if(!item.isSpace()) {
                    item.setHasIconShow(true);
                }
            }
        }
        addedAdapter.notifyDataSetChanged();
        unAddedAdapter.notifyDataSetChanged();
    }


    private class ChannelAdapter extends CommonAdapter<MoudleChildBean> {
        private boolean isAddedChannel;

        public ChannelAdapter(Context context, int layoutId, List<MoudleChildBean> datas, boolean isAddedChannel) {
            super(context, layoutId, datas);
            this.isAddedChannel = isAddedChannel;
        }

        @Override
        protected void convert(ViewHolder holder, MoudleChildBean channelItem,  int position) {
            LinearLayout itemLayout = (LinearLayout) holder.getConvertView().findViewById(R.id.layout_item);
            TextView title = (TextView) holder.getConvertView().findViewById(R.id.tv_item);
            ImageView iconButton = (ImageView) holder.getConvertView().findViewById(R.id.bt_icon);
            ImageView itemImagView = (ImageView) holder.getConvertView().findViewById(R.id.iv_item);
            setItemLayoutSize(itemLayout);
            setIconDrawble(iconButton , isAddedChannel);
            setIconButtonListener(iconButton ,channelItem,isAddedChannel);

            if(channelItem.isSpace()){
                iconButton.setVisibility(GONE);
                itemImagView.setVisibility(GONE);
            }else{
                iconButton.setVisibility(VISIBLE);
                itemImagView.setVisibility(VISIBLE);
            }

            if(channelItem.isHasIconShow() && !channelItem.isNotMove()){
                iconButton.setVisibility(VISIBLE);
            }else{
                iconButton.setVisibility(GONE);
            }




            title.setTextColor(channelItemTxColor);
            title.setText(channelItem.getMoudleChildName());
        }
    }

    /**
     * 设置Icon的图标
     * @param iconImageView
     * @param isAddedChannel
     */
    private void setIconDrawble(ImageView iconImageView, boolean isAddedChannel) {
        if(isAddedChannel){
            iconImageView.setImageDrawable(getContext().getResources().getDrawable(R.drawable.icon_banner));
        }else{
            iconImageView.setImageDrawable(getContext().getResources().getDrawable(R.drawable.icon_moudle_add));
        }
    }


    private void setItemLayoutSize(LinearLayout itemLayout) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) itemLayout.getLayoutParams();
        params.width = mItemSize;
        params.height = (int) (mItemSize / mScale);
        itemLayout.setLayoutParams(params);
    }

    /**
     * 设置icon按钮的监听
     * @param iconButton    icon按钮
     * @param channelItem    channelItem对象
     */
    private void setIconButtonListener(ImageView iconButton, MoudleChildBean channelItem ,final boolean flag) {
        iconButton.setTag(channelItem);
        iconButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                mNowClickTime =System.currentTimeMillis();
                if(mNowClickTime - mPreClickTime > mDuration) {
                    MoudleChildBean item = (MoudleChildBean) view.getTag();
                    if (!flag) {
                        addDataToList(addedChannels, addedAdapter, item.getPosition(),
                                unAddedChannels, unAddedAdapter,flag);
                    } else {
                        addDataToList(unAddedChannels, unAddedAdapter, item.getPosition(),
                                addedChannels, addedAdapter,flag);
                    }
                    setIconDrawble((ImageView) view, !flag);
                    initListPosition(addedChannels);
                    initListPosition(unAddedChannels);
                    mPreClickTime = mNowClickTime;
                }
            }
        });
    }

    /**
     * 对List里面Position进行重新赋值
     * @param channels
     */
    private void initListPosition(ArrayList<MoudleChildBean> channels) {
        for(int i = 0 ; i < channels.size() ; i++){
            channels.get(i).setPosition(i);
        }
    }
//
//    private class SpacesItemDecoration extends RecyclerView.ItemDecoration {
//        private int space;
//
//        public SpacesItemDecoration(int space) {
//            this.space = space;
//        }
//
//        @Override
//        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//            //不是第一个的格子都设一个左边和底部的间距
//            outRect.left = space;
//            outRect.bottom = space;
//            //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
//            if (parent.getChildLayoutPosition(view) %colums==0) {
//                outRect.left = 0;
//            }
//        }
//    }

    public RecyclerView getAddedRecyclerView() {
        return addedRecyclerView;
    }

    public RecyclerView getUnaddedRecyclerView() {
        return unaddedRecyclerView;
    }

    /**
     * 获取已添加栏目banner可以自定义文字内容和样式
     *
     * @return
     */
    public TextView getCategaryAddedTopView() {
        return categaryAddedTopView;
    }

    /**
     * 获取未添加栏目banner 可以自定义文字内容和样式
     *
     * @return
     */
    public TextView getCategrayUnAddedTopView() {
        return categrayUnAddedTopView;
    }

    public void showPahtAnim(boolean showPahtAnim) {
        this.showPahtAnim = showPahtAnim;
    }

    public void setOnChannelItemClicklistener(OnChannelItemClicklistener onChannelItemClicklistener) {
        this.onChannelItemClicklistener = onChannelItemClicklistener;
    }

    public void setUserActionListener(UserActionListener userActionListener) {
        this.userActionListener = userActionListener;
    }

    public void setColums(int colums) {
        this.colums = colums;
    }

    public void setColumnSpace(int columnSpace) {
        this.columnSpace = columnSpace;
    }

    public void setFixedPos(int fixedPos) {
        this.fixedPos = fixedPos;
    }

    /**
     * 设置频道字体颜色
     *
     * @param channelItemTxColor 颜色值
     */
    public void setChannelItemTxColor(int channelItemTxColor) {
        this.channelItemTxColor = channelItemTxColor;
    }

    /**
     * 设置频道字体大小
     *
     * @param pixel 大小（pixel）
     */
    public void setChannelItemTxSizePixel(int pixel) {
        this.channelItemTxSize = channelItemTxSize;
    }

    /**
     * 设置频道字体大小(sp)
     *
     * @param sp 大小（sp）
     */
    public void setChannelItemTxSizeSP(int sp) {
        this.channelItemTxSize = MeasureUtil.sp2px(getContext(), channelItemTxSize);
    }

    public void setCategoryAddedBannerBg(int categoryAddedBannerBg) {
        this.categoryAddedBannerBg = categoryAddedBannerBg;
        categaryAddedTopView.setBackgroundResource(categoryAddedBannerBg);
    }

    public void setCategoryUnAddedBannerBg(int categoryUnAddedBannerBg) {
        this.categoryUnAddedBannerBg = categoryUnAddedBannerBg;
        categrayUnAddedTopView.setBackgroundResource(categoryUnAddedBannerBg);
    }

    public void setCategoryBannerTXsize(int pixel) {
        categaryAddedTopView.setTextSize(TypedValue.COMPLEX_UNIT_PX, pixel);
        categrayUnAddedTopView.setTextSize(TypedValue.COMPLEX_UNIT_PX, pixel);
    }

    public void setCategoryBannerTXColor(int colorValue) {
        categaryAddedTopView.setTextColor(colorValue);
        categrayUnAddedTopView.setTextColor(colorValue);
    }

    public ArrayList<MoudleChildBean> getAddedChannels() {
        return addedChannels;
    }

    public ArrayList<MoudleChildBean> getUnAddedChannels() {
        return unAddedChannels;
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        FloatItemViewManager.removeFloawAdView(getContext());
    }

    /**
     * 描述：频道item的红点提示处理回调接口
     * author: zhl 2017-3-20
     *
     */
    public interface RedDotRemainderListener {
        /**
         * 已添加栏目是否显示红点提示view
         * @param itemView
         * @param position
         * @return return true show the bgabadgeTipView otherwish not show
         */
        public boolean showAddedChannelBadge(BGABadgeTextView itemView, int position);

        /**
         * 未添加栏目是否显示红点提示view
         * @param itemView
         * @param position
         * @return return true show the bgabadgeTipView otherwish not show
         */
        public boolean showUnAddedChannelBadge(BGABadgeTextView itemView, int position);

        /**
         * 处理已添加栏目红点提示view 通过BGABadgeTextView.getBadgeViewHelper()可以设置红点提示view一些属性 如：间距 显示样式 文字大小等等
         * @param itemView
         * @param position
         */
        public void handleAddedChannelReddot(BGABadgeTextView itemView, int position);
        /**
         * 处理已添加栏目红点提示view 通过BGABadgeTextView.getBadgeViewHelper()可以设置红点提示view一些属性 如：间距 显示样式 文字大小等等
         * @param itemView
         * @param position
         */
        public void handleUnAddedChannelReddot(BGABadgeTextView itemView, int position);

        /**
         * 拖拽提示view消失回调
         * @param itemView
         * @param position
         */
        public void OnDragDismiss(BGABadgeTextView itemView, int position);

    }
}
